﻿///<reference path="../../ExtJs/vswd-ext_2.2.js" />

var hidClientImgID;
var imgClientImgID;

Ext.onReady(function() {
    Ext.QuickTips.init();
    // 本地加载图片代码
    Ext.BLANK_IMAGE_URL = strPath + 'extjs/resources/images/default/s.gif';

    document.getElementById("td_maitou_image").style.height = parent.Ext.get("ContentFrame").getHeight() - 145;
    document.getElementById("img_maitou_image").style.width = (parent.Ext.get("ContentFrame").getWidth() / 2 - 80) * 0.93;
    document.getElementById("img_diaopai_image").style.width = (parent.Ext.get("ContentFrame").getWidth() / 2 - 80) * 0.93;

    //图片窗口
    winClientImg = new Ext.Window({
        width: parent.Ext.get("ContentFrame").getWidth() - 60,
        height: parent.Ext.get("ContentFrame").getHeight() - 60,
        layout: 'fit',
        plain: true,
        constrain: true, // windows不超过浏览器
        autoScroll: 'true',
        closeAction: 'hide',
        modal: true,
        deferredRender: false,
        resizable: false,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        contentEl: 'divClientImg',
        bodyStyle: 'border-top:0;padding:2 2 2 2;background:#E5E2EE;',
        closeAction: 'hide',
        listeners: {
            rowselect: function(sm, row, rec) {
                //选择列事件
            }
        }
    });

})

function btnSaveClient_Click() {
    var clientFileds = "";
    var alertInfo = ""; //警告提示信息

    //客户表相关信息(client)
    var filed_client_code = Ext.get("ipt_client_code").dom.value;
    var filed_client_name = Ext.get("ipt_client_name").dom.value;
    var filed_lianxiren = Ext.get("ipt_lianxiren").dom.value;
    var filed_telephone = Ext.get("ipt_telephone").dom.value;
    var filed_address = Ext.get("ipt_address").dom.value;
    var filed_maokuan = Ext.get("ipt_maokuan").dom.value;
    var filed_maitou = Ext.get("ipt_maitou").dom.value;
    var filed_diaopai = Ext.get("ipt_diaopai").dom.value;
    var filed_maitou_image = Ext.get("hid_maitou_image").dom.value;
    var filed_diaopai_image = Ext.get("hid_diaopai_image").dom.value;

    var clientFileds = "client_code,client_name,lianxiren,telephone,address,maokuan,maitou,diaopai,maitou_image,diaopai_imageξψ" + filed_client_code + "ψ,ψ" + filed_client_name + "ψ,ψ" + filed_lianxiren + "ψ,ψ" + filed_telephone + "ψ,ψ" + filed_address + "ψ,ψ" + filed_maokuan + "ψ,ψ" + filed_maitou + "ψ,ψ" + filed_diaopai + "ψ,ψ" + filed_maitou_image + "ψ,ψ" + filed_diaopai_image + "ψ";

    //提示信息
    if (filed_client_code == null || filed_client_code == "")
        alertInfo += "<span style='font-weight:bold;'>编号</span>不能为空！</br>";
    if (filed_client_name == null || filed_client_name == "")
        alertInfo += "<span style='font-weight:bold;'>客户名</span>不能为空！</br>";
    if (alertInfo != null && alertInfo != "") {
        Ext.MessageBox.alert("提示", "<span style='line-height:18px;'>" + alertInfo + "</span>");
        return;
    }

    //Ajax交互
    var myMask = new Ext.LoadMask(Ext.getBody(), {
        msg: "正在保存数据..."
    });
    myMask.show();

    var strUrl = strPath + 'GGFW/DocumentsManage/ClientCommand.fwf?Method=SaveClient'
    Ext.Ajax.request({
        url: strUrl,
        method: 'POST',
        params: {
            clientFileds: clientFileds
        },
        failure: function(response, options) {
            myMask.hide();
            ReturnValue = Ext.MessageBox.alert("警告", "网络异常或登录过期，请重新登录！");
        },
        success: function(response, options) {
            // 保存返回的信息
            myMask.hide();
            var json = response.responseText;
            var obj = parseJsonResult(json);

            if (!obj.Success) {
                showMessage("错误！", "保存数据出错！", obj.Message);
            }
            else {
                if (obj.Message != null && obj.Message.trim() != '') {
                    Ext.MessageBox.alert("警告", obj.Message);
                    return;
                }
                else {

                    Ext.MessageBox.confirm("询问", '保存客户信息成功，是否继续添加？', function(btn) {
                        if (btn == "yes")
                            window.location.href('ClientAdd.aspx');
                        else
                            window.location.href('ClientList.aspx');
                    });
                }
            }
        }
    });
}

//打开图片上传窗口
function showWinClientImg(imgImgID, hidImgID) {
    imgClientImgID = imgImgID;
    hidClientImgID = hidImgID;
    document.getElementById("imgClient").src = "../UploadFile/" + document.getElementById(hidClientImgID).value;
    document.getElementById(imgClientImgID).src = "../UploadFile/" + document.getElementById(hidClientImgID).value;
    document.getElementById("imgClient").style.height = parent.Ext.get("ContentFrame").getHeight() - 160;
    winClientImg.setTitle("图片上传更新");
    document.getElementById("span_info").innerHTML = "请选择图片文件（*.jpg,*.gif,*.png,*.bmp)";
    controlShow('divClientImg');
    winClientImg.show();
}

function CloseWinClientImg() {
    winClientImg.hide();
}